import os
import requests
import subprocess

# 文件下载 URL
url = "https://raw.githubusercontent.com/lstprjct/IDM-Activation-Script/main/IAS_0.8.cmd"

# 存储在系统临时目录
file_path = os.path.join(os.getenv("TEMP"), "IAS.cmd")

try:
    # 发送请求下载文件
    response = requests.get(url, timeout=10)
    response.raise_for_status()  # 确保请求成功

    # 将内容写入文件
    with open(file_path, "wb") as file:
        file.write(response.content)

    print(f"文件已下载: {file_path}")

    # 执行 cmd 脚本
    subprocess.run(["cmd", "/c", file_path], check=True)

except requests.exceptions.RequestException as e:
    print(f"下载失败: {e}")

except subprocess.CalledProcessError as e:
    print(f"执行失败: {e}")

finally:
    # 删除文件
    if os.path.exists(file_path):
        os.remove(file_path)
        print("文件已删除")
